package com.crazymaker.springcloud.cloud.center.zuul.config;

import org.springframework.beans.BeansException;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.web.DefaultSecurityFilterChain;
import org.springframework.session.web.http.SessionRepositoryFilter;

import javax.servlet.Filter;
import java.util.List;

@Configuration
public class SpringSecurityConfig implements BeanPostProcessor {
    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        if (bean.getClass().isAssignableFrom(DefaultSecurityFilterChain.class)) {
            DefaultSecurityFilterChain filterChain = (DefaultSecurityFilterChain) bean;
            List<Filter> filters = filterChain.getFilters();
            // 删除SessionRepositoryFilter过滤器
            filters.stream().filter(item->item.getClass().isAssignableFrom(SessionRepositoryFilter.class));
        }
        return bean;
    }
}
